import Layout from "./Layout/Layout.tsx";
import { useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api";
import Error from "./Components/Error/Error.tsx";
import { store } from "./store/store.ts";
import { Provider } from "react-redux";
import Loading from "./Components/Loading/Loaindg.tsx";

function App() {
  const [loading, setLoading] = useState(true);
  const [status, setStatus] = useState(false);
  const init = () => {
    setLoading(true);
    invoke("is_lcu_success")
      .then((res) => {
        setStatus(res as boolean);
        // setStatus(false);
      })
      .finally(() => {
        setLoading(false);
      });
  };
  useEffect(() => {
    init();
  }, []);
  if (loading) {
    return <Loading />;
  } else {
    return (
      <>
        {status ? (
          <Provider store={store}>
            <Layout />
          </Provider>
        ) : (
          <Error init={init}></Error>
        )}
      </>
    );
  }
}

export default App;
